package com.project.service.impl;

import com.project.bean.ClassBean;
import com.project.mapper.IClassMapper;
import com.project.service.IClassService;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class ClassServiceImpl extends BaseService implements IClassService {

    @Override
    public List<ClassBean> findAllClass() {
        SqlSession session = this.getSession();
        IClassMapper mapper = session.getMapper(IClassMapper.class);
        List<ClassBean> list = mapper.findAllClass();
        session.close();
        return list;
    }

    @Override
    public void addClass(ClassBean classBean) {
        SqlSession session = this.getSession();
        IClassMapper mapper = session.getMapper(IClassMapper.class);
        mapper.addClass(classBean);
        session.commit();
        session.close();
    }

    @Override
    public boolean deClass(Integer id) {
        SqlSession session = this.getSession();
        IClassMapper mapper = session.getMapper(IClassMapper.class);
        ClassBean classBean = mapper.findByClassId(id);
        if (classBean != null){
            mapper.deClass(id);
            session.commit();
            session.close();
            return true;
        }else {
            session.close();
            return true;
        }
    }
}
